using ChatGPT.Repository;
using OpenAI.GPT3.Extensions;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.Configure<MongoConfig>(
    builder.Configuration.GetSection("MongoDBConfig"));

builder.Services.AddScoped(typeof(IMongoRepository<>), typeof(MongoRepository<>));

builder.Services.AddControllers();
builder.Services.AddOpenAIService(x => { x.ApiKey = "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"; });
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddCors(options =>
{
    var _corsHosts = builder.Configuration.GetValue("CorsHosts", string.Empty)
        .Split(",", StringSplitOptions.RemoveEmptyEntries);
    options.AddPolicy("default", policy =>
    {
        policy.WithOrigins(_corsHosts)
            .AllowAnyHeader()
            .AllowAnyMethod()
            .AllowCredentials();
    });
});

var app = builder.Build();
app.UseCors("default");

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();